package com.example.springbootmybatis.utility;

import java.io.*;

/**
 * @title: StringUtil
 * @Author Tan
 * @Date: 2021/7/2 17:16
 * @Version 1.0
 */
public class CommonUtil {
    /**
     * @Description: 序列化
     * @Author banyunjian
     * @Date: 2021/7/7 17:48
     */
    public <T> void serializableInTo(String path,T obj) throws Exception{
        File io= new File(path);
        ObjectOutputStream oos= new ObjectOutputStream(new FileOutputStream(io));
        oos.writeObject(obj);//把类对象序列化
        oos.close();
    }

    /**
     * @Description: 反序列化
     * @Author banyunjian
     * @Date: 2021/7/7 17:48
     */
    public <T> T serializableOutFrom(String path) throws Exception{
        File io= new File(path);
        ObjectInputStream ois= new ObjectInputStream(new FileInputStream(io));
        T result= (T)ois.readObject();//把类对象序列化
        ois.close();
        return result;
    }
}
